import {Injectable} from '@angular/core';
import {HttpService} from '../lib/service/http.service';
import {appletApiUrl} from '../../config/api';
import { of } from 'rxjs/observable/of';
import { map } from 'rxjs/operators/map';
import {LocalStorageService} from '../lib/service/local-storage.service';
import {Observable} from 'rxjs/Observable';
import {Shop} from './shop';
import {SHOPS} from './shops';
import {Subject} from 'rxjs/Subject';

@Injectable()
export class MyShopService {
  // shopid$: Observable<number>;
    shopid: any;
    shopid$: Subject<any> = new Subject<number>();
  // shopid = new Subject<number>();
  // shopid$ = this.shopid.asObservable();
  // subObservable$ = this.sub.asObservable();
  // sub  = new Observable((observer) => {
  //   observer.next(this.shopid);
  // });

  constructor(private httpService: HttpService, private localStorageService: LocalStorageService) {
  }
    getMyShop() {
      const url = `${appletApiUrl}/backend/shop/index_my` ;
      console.log('------999----------');
      return this.httpService.httpPostAuth(url, {}).map(res => res);
    }

    // getShop(id: number | string) {
    //  return Observable.create((observer) => {
    //    observer.next(this.shopid);
    //  });
     // return  this.getMyShop().pipe(
     //   map ((shops: Shop[]) => shops.find( shop => shop.id === +id))
     // );
    // }
    setShop(id: any) {
      this.shopid = id;
      this.shopid$.next(this.shopid);
    }
    getShop(): Observable<any> {
      return this.shopid$.asObservable();
    }
    // getShop(): Observable<number> {
    //   return this.shopid$;
    // }

}
